//
//  NSString+Common.m
//  CToolBox
//
//  Created by crj on 16/10/14.
//  Copyright © 2016年 oyf. All rights reserved.
//

#import "NSString+Common.h"
#import <CommonCrypto/CommonDigest.h>


@implementation NSString (Common)

+ (NSString *)getUUID
{
    CFUUIDRef uuidObj = CFUUIDCreate(nil);//create a new UUID
    
    //get the string representation of the UUID
    
    NSString *uuidString = (__bridge_transfer NSString *)CFUUIDCreateString(nil, uuidObj);
    
    CFRelease(uuidObj);
    
    return uuidString ;
    
}

- (NSString *)MD5String {
    const char *cstr = [self UTF8String];
    unsigned char result[16];
    CC_MD5(cstr, (CC_LONG)strlen(cstr), result);
    return [NSString stringWithFormat:
            @"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3],
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ];
}

+ (NSString *)spaceOfString:(NSString *)spaceString strings:(NSArray *)strings{

    if(!strings || !spaceString){
        return @"";
    }
    if(strings.count==0){
        return @"";
    }
    
    NSString *resultString = @"";
    
    for(int i=0; i<strings.count; i++){
        if(i==0){
            resultString = strings[i];
        }else{
            resultString = [NSString stringWithFormat:@"%@%@%@",resultString,spaceString,strings[i]];
        }
    }
    return resultString;
    
}

@end
